<?php

namespace App\Http\Controllers;


use App\Services\CustomerService;
use App\Transformer\CustomerRecordsTransformer;
use App\Transformer\CustomerTransformer;
use Dingo\Api\Http\Request;

class CustomerController extends Controller
{

    /**
     * 客户查询
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @author thanatos thanatos915@163.com
     */
    public function search(Request $request)
    {
        return $this->response->paginator(CustomerService::search($request), new CustomerTransformer());
    }

    /**
     * 新增客户
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @author thanatos thanatos915@163.com
     */
    public function create(Request $request)
    {
        return $this->response->item(CustomerService::createAndUpdate($request, 0), new CustomerTransformer());
    }

    /**
     * 客户转移
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @author thanatos thanatos915@163.com
     */
    public function move(Request $request)
    {
        CustomerService::move($request);
        return $this->response->noContent();
    }

    /**
     * 客户详情
     * @param $id
     * @return \Dingo\Api\Http\Response
     * @author thanatos thanatos915@163.com
     */
    public function show($id)
    {
        return $this->response->item(CustomerService::info($id), new CustomerTransformer());
    }

    /**
     * 客户跟进
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @author thanatos thanatos915@163.com
     */
    public function follow(Request $request)
    {
        CustomerService::follow($request);
        return $this->response->noContent();
    }

    /**
     * 获取跟进记录
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @author thanatos thanatos915@163.com
     */
    public function records(Request $request)
    {
        return $this->response->paginator(CustomerService::records($request), new CustomerRecordsTransformer());
    }

    /**
     * 批量导入
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @author thanatos thanatos915@163.com
     */
    public function import(Request $request)
    {
        CustomerService::import($request);
        return $this->response->noContent();
    }
    /**
     * 分配列表
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @author thanatos thanatos915@163.com
     */
    public function importList(Request $request)
    {
        return $this->response->paginator(CustomerService::importList($request), new CustomerTransformer());
    }

    /**
     * 确认分配
     * @author thanatos thanatos915@163.com
     */
    public function confirmAssigned(Request $request)
    {
        CustomerService::confirmAssigned($request);
        return $this->response->noContent();
    }

    /**
     * 删除批量导入
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @author thanatos thanatos915@163.com
     */
    public function assignedDelete(Request $request)
    {
        CustomerService::assignedDelete($request);
        return $this->response->noContent();
    }


}
